﻿// ----------------------------------------------------------------
// Description : 实体类,该文件由MyGeneration生成
// Author      : 
// Create date : 2010/7/22
// ----------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace ITOMMS.Entity
{
    /// <summary>
    ///	tbPurchaseInfo Entity
    ///	tbPurchaseInfo Entity进货情况表
    /// </summary>
    [Serializable]
    public class tbPurchaseInfoEntity : BaseEntity<tbPurchaseInfoEntity, int>
    {

        #region 私有成员

        private int _ID;
        private string _名称;
        private string _编号;
        private int? _供应商;
        private string _品牌;
        private string _类别;
        private string _型号;
        private string _单位;
        private string _规格;
        private decimal? _采购价;
        private decimal? _批发价;
        private decimal? _零售价;
        private string _送货人;
        private string _数量;
        private DateTime? _进货时间;
        private string _备注;
        private bool? _是否包含税;
        private DateTime? _CreateDate;
        private int? _CreateBy;
        private DateTime? _ModifyDate;
        private int? _ModifyBy;
        private int _SEQNO;
        #endregion



        #region 默认( 空 ) 构造函数
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public tbPurchaseInfoEntity()
        {
            _ID = 0;
            _名称 = String.Empty;
            _编号 = String.Empty;
            _供应商 = null;
            _品牌 = String.Empty;
            _类别 = String.Empty;
            _型号 = String.Empty;
            _单位 = String.Empty;
            _规格 = String.Empty;
            _采购价 = null;
            _批发价 = null;
            _零售价 = null;
            _送货人 = String.Empty;
            _数量 = String.Empty;
            _进货时间 = null;
            _备注 = String.Empty;
            _是否包含税 = null;
            _CreateDate = null;
            _CreateBy = null;
            _ModifyDate = null;
            _ModifyBy = null;
            _SEQNO = 0;
        }
        #endregion

        #region 属性值校验

        /// <summary>
        /// 属性值校验
        /// </summary>
        public bool CheckValues()
        {
            bool bResult = true;
            string strError = "";

            if (_ID == 0)
            {
                bResult = false;
                strError += "\r\n 非空值不能为: " + _ID;
            }

            if (!bResult)
                throw new ArgumentOutOfRangeException(strError);
            return bResult;

        }

        #endregion




        #region Required Fields Only Constructor

        /// <summary>
        /// required (not null) fields only constructor
        /// </summary>
        public tbPurchaseInfoEntity(
        int para_ID)
            : this()
        {
            _ID = para_ID;
            _名称 = String.Empty;
            _编号 = String.Empty;
            _供应商 = null;
            _品牌 = String.Empty;
            _类别 = String.Empty;
            _型号 = String.Empty;
            _单位 = String.Empty;
            _规格 = String.Empty;
            _采购价 = null;
            _批发价 = null;
            _零售价 = null;
            _送货人 = String.Empty;
            _数量 = String.Empty;
            _进货时间 = null;
            _备注 = String.Empty;
            _是否包含税 = null;
            _CreateDate = null;
            _CreateBy = null;
            _ModifyDate = null;
            _ModifyBy = null;
        }
        #endregion


        #region 公有属性

        /// <summary>
        /// 行号，顺序号。系统默认的属性,对这个属性不要作操作.属性值在架构中已经处理
        /// </summary>
        public virtual int SEQNO
        {
            get { return _SEQNO; }
            set { _SEQNO = value; }
        }


        /// <summary>
        /// IDID
        /// </summary>		
        public virtual int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        /// <summary>
        /// 名称名称
        /// </summary>		
        public virtual string 名称
        {
            get { return _名称; }
            set
            {

                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for 名称", value, value.ToString());

                _名称 = value;
            }
        }

        /// <summary>
        /// 编号编号
        /// </summary>		
        public virtual string 编号
        {
            get { return _编号; }
            set
            {

                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for 编号", value, value.ToString());

                _编号 = value;
            }
        }

        /// <summary>
        /// 供应商供应商
        /// </summary>		
        public virtual int? 供应商
        {
            get { return _供应商; }
            set { _供应商 = value; }
        }

        /// <summary>
        /// 品牌品牌
        /// </summary>		
        public virtual string 品牌
        {
            get { return _品牌; }
            set
            {

                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for 品牌", value, value.ToString());

                _品牌 = value;
            }
        }

        /// <summary>
        /// 类别类别
        /// </summary>		
        public virtual string 类别
        {
            get { return _类别; }
            set
            {

                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for 类别", value, value.ToString());

                _类别 = value;
            }
        }

        /// <summary>
        /// 型号型号
        /// </summary>		
        public virtual string 型号
        {
            get { return _型号; }
            set
            {

                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for 型号", value, value.ToString());

                _型号 = value;
            }
        }

        /// <summary>
        /// 单位单位
        /// </summary>		
        public virtual string 单位
        {
            get { return _单位; }
            set
            {

                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for 单位", value, value.ToString());

                _单位 = value;
            }
        }

        /// <summary>
        /// 规格规格
        /// </summary>		
        public virtual string 规格
        {
            get { return _规格; }
            set
            {

                if (value != null)
                    if (value.Length > 50)
                        throw new ArgumentOutOfRangeException("Invalid value for 规格", value, value.ToString());

                _规格 = value;
            }
        }

        /// <summary>
        /// 采购价采购价
        /// </summary>		
        public virtual decimal? 采购价
        {
            get { return _采购价; }
            set { _采购价 = value; }
        }

        /// <summary>
        /// 批发价批发价
        /// </summary>		
        public virtual decimal? 批发价
        {
            get { return _批发价; }
            set { _批发价 = value; }
        }

        /// <summary>
        /// 零售价零售价
        /// </summary>		
        public virtual decimal? 零售价
        {
            get { return _零售价; }
            set { _零售价 = value; }
        }

        /// <summary>
        /// 送货人
        /// </summary>		
        public virtual string 送货人
        {
            get { return _送货人; }
            set
            {

                if (value != null)
                    if (value.Length > 100)
                        throw new ArgumentOutOfRangeException("Invalid value for 送货人", value, value.ToString());

                _送货人 = value;
            }
        }

        /// <summary>
        /// 数量
        /// </summary>		
        public virtual string 数量
        {
            get { return _数量; }
            set
            {

                if (value != null)
                    if (value.Length > 100)
                        throw new ArgumentOutOfRangeException("Invalid value for 数量", value, value.ToString());

                _数量 = value;
            }
        }

        /// <summary>
        /// 进货时间进货时间
        /// </summary>		
        public virtual DateTime? 进货时间
        {
            get { return _进货时间; }
            set { _进货时间 = value; }
        }

        /// <summary>
        /// 备注备注
        /// </summary>		
        public virtual string 备注
        {
            get { return _备注; }
            set
            {

                if (value != null)
                    if (value.Length > 500)
                        throw new ArgumentOutOfRangeException("Invalid value for 备注", value, value.ToString());

                _备注 = value;
            }
        }

        /// <summary>
        /// 是否包含税是否包含税
        /// </summary>		
        public virtual bool? 是否包含税
        {
            get { return _是否包含税; }
            set { _是否包含税 = value; }
        }

        /// <summary>
        /// CreateDate创建时间
        /// </summary>		
        public virtual DateTime? CreateDate
        {
            get { return _CreateDate; }
            set { _CreateDate = value; }
        }

        /// <summary>
        /// CreateBy创建人
        /// </summary>		
        public virtual int? CreateBy
        {
            get { return _CreateBy; }
            set { _CreateBy = value; }
        }

        /// <summary>
        /// ModifyDate修改时间
        /// </summary>		
        public virtual DateTime? ModifyDate
        {
            get { return _ModifyDate; }
            set { _ModifyDate = value; }
        }

        /// <summary>
        /// ModifyBy修改人
        /// </summary>		
        public virtual int? ModifyBy
        {
            get { return _ModifyBy; }
            set { _ModifyBy = value; }
        }



        #endregion


        #region DAO操作


        /// <summary>
        /// 获取所有实体的列表
        /// </summary>
        /// <returns></returns>
        public override List<tbPurchaseInfoEntity> GetAll()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [ID],[名称],[编号],[供应商],[品牌],[类别],[型号],[单位],[规格],[采购价],[批发价],[零售价],[送货人],[数量],[进货时间],[备注],[是否包含税],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_PurchaseInfo] ");

            List<tbPurchaseInfoEntity> list = new List<tbPurchaseInfoEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                int seq = 0;
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }

        /// <summary>
        /// 获取所有实体的列表总行数
        /// </summary>
        /// <returns></returns>
        public override int GetTotalRecords()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  select count([ID])  from [tb_PurchaseInfo] ");

            Database db = GetDatabase();
            return (int)db.ExecuteScalar(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获取所有实体的列表总行数
        /// </summary>
        /// <returns></returns>
        public override int GetTotalRecords(string sqlCondition)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  select count([ID])  from [tb_PurchaseInfo]  ");

            if (sqlCondition.Trim() != "")
            {
                strSql.Append(" where " + sqlCondition);
            }
            Database db = GetDatabase();
            return (int)db.ExecuteScalar(CommandType.Text, strSql.ToString());
        }


        /// <summary>
        /// 按条件查询,得到一页的对应的结果列表
        /// </summary>
        /// <param name="strWhere">条件</param>
        /// <param name="PageSize">每页大小</param>
        /// <param name="CurrentPageIndex">当前页码</param>
        /// <returns></returns>
        public override List<tbPurchaseInfoEntity> GetAllByQuery(string strWhere, int PageSize, int CurrentPageIndex)
        {
            StringBuilder strSql = new StringBuilder();
            if (strWhere.Contains("order".ToLower()))
            {
                throw new Exception("分页查询的sql条件中不能包括排序子句，请调用重载方法实现有条件的排序筛选");
            }

            strSql.Append("select top ").Append(PageSize).Append("  [ID],[名称],[编号],[供应商],[品牌],[类别],[型号],[单位],[规格],[采购价],[批发价],[零售价],[送货人],[数量],[进货时间],[备注],[是否包含税],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_PurchaseInfo] where ");

            if (strWhere.Trim() != "")
            {
                strSql.Append("  " + strWhere + " and ");
            }
            strSql.Append(" ID not in ( ");
            strSql.Append(" select top ").Append(PageSize * (CurrentPageIndex - 1)).Append("  [ID] from [tb_PurchaseInfo] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" ) ");

            List<tbPurchaseInfoEntity> list = new List<tbPurchaseInfoEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                int seq = PageSize * (CurrentPageIndex - 1);
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }


        /// <summary>
        /// 按条件查询,得到一页的对应的结果列表
        /// </summary>
        /// <param name="strWhere">条件</param>
        /// <param name="PageSize">每页大小</param>
        /// <param name="CurrentPageIndex">当前页码</param>
        /// <param name="strSort">ex:order by id desc</param>
        /// <returns></returns>
        public override List<tbPurchaseInfoEntity> GetAllByQuery(string strWhere, string strSort, int PageSize, int CurrentPageIndex)
        {
            StringBuilder strSql = new StringBuilder();
            if (strWhere.Contains("order".ToLower()))
            {
                throw new Exception("分页查询的sql条件中不能包括排序子句，请调用重载方法实现有条件的排序筛选");
            }

            strSql.Append("select top ").Append(PageSize).Append("  [ID],[名称],[编号],[供应商],[品牌],[类别],[型号],[单位],[规格],[采购价],[批发价],[零售价],[送货人],[数量],[进货时间],[备注],[是否包含税],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_PurchaseInfo] where ");

            if (strWhere.Trim() != "")
            {
                strSql.Append("  " + strWhere + " and ");
            }
            strSql.Append(" ID not in ( ");
            strSql.Append(" select top ").Append(PageSize * (CurrentPageIndex - 1)).Append("  [ID] from [tb_PurchaseInfo] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere + " ").Append(strSort);
            }
            strSql.Append(" ) ").Append(strSort);

            List<tbPurchaseInfoEntity> list = new List<tbPurchaseInfoEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                int seq = PageSize * (CurrentPageIndex - 1);
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }


        /// <summary>
        /// 按条件查询,得到对应的结果列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public override List<tbPurchaseInfoEntity> GetAllByQuery(string strWhere)
        {
            strWhere = SQLInjectionFilter(strWhere);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [ID],[名称],[编号],[供应商],[品牌],[类别],[型号],[单位],[规格],[采购价],[批发价],[零售价],[送货人],[数量],[进货时间],[备注],[是否包含税],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from tb_PurchaseInfo ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tbPurchaseInfoEntity> list = new List<tbPurchaseInfoEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                int seq = 0;
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }



        /// <summary>
        /// 按条件查询,得到对应的结果列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <param name="parameters">sql条件中的参数</param>
        /// <returns></returns>
        public override List<tbPurchaseInfoEntity> GetAllByQuery(string strWhere, List<IDataParameter> parameters)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [ID],[名称],[编号],[供应商],[品牌],[类别],[型号],[单位],[规格],[采购价],[批发价],[零售价],[送货人],[数量],[进货时间],[备注],[是否包含税],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_PurchaseInfo] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tbPurchaseInfoEntity> list = new List<tbPurchaseInfoEntity>();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            foreach (IDataParameter sp in parameters)
            {
                db.AddInParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Value);
            }

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                int seq = 0;
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }






        /// <summary>
        /// 获取按条件查询以后的结果列表的前指定rowNumber行记录
        /// </summary>
        /// <param name="strWhere">不带where关键字的SQL条件语句</param>
        /// <param name="rowNumber"></param>
        /// <returns></returns>
        public override List<tbPurchaseInfoEntity> GetAllByQuery(string strWhere, List<IDataParameter> parameters, int rowNumber)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top ").Append(rowNumber).Append("  [ID],[名称],[编号],[供应商],[品牌],[类别],[型号],[单位],[规格],[采购价],[批发价],[零售价],[送货人],[数量],[进货时间],[备注],[是否包含税],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_PurchaseInfo] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tbPurchaseInfoEntity> list = new List<tbPurchaseInfoEntity>();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            foreach (IDataParameter sp in parameters)
            {
                db.AddInParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Value);
            }

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                int seq = 0;
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }


        /// <summary>
        /// 获取按条件查询以后的结果列表的前指定rowNumber行记录
        /// </summary>
        /// <param name="strWhere">不带where关键字的SQL条件语句: AND AA=@AA</param>
        /// <param name="rowNumber"></param>
        /// <returns></returns>
        public override List<tbPurchaseInfoEntity> GetAllByQuery(string strWhere, int rowNumber)
        {
            strWhere = SQLInjectionFilter(strWhere);
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top ").Append(rowNumber).Append("  [ID],[名称],[编号],[供应商],[品牌],[类别],[型号],[单位],[规格],[采购价],[批发价],[零售价],[送货人],[数量],[进货时间],[备注],[是否包含税],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_PurchaseInfo] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where  " + strWhere);
            }
            List<tbPurchaseInfoEntity> list = new List<tbPurchaseInfoEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                int seq = 0;
                while (dataReader.Read())
                {
                    seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }







        /// <summary>
        /// 按主键查询对应的实体
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        public override tbPurchaseInfoEntity GetById(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [ID],[名称],[编号],[供应商],[品牌],[类别],[型号],[单位],[规格],[采购价],[批发价],[零售价],[送货人],[数量],[进货时间],[备注],[是否包含税],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] from [tb_PurchaseInfo]  where ID= @ID ");

            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, id);
            tbPurchaseInfoEntity entity = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    entity = ReaderBind(dataReader);
                }
            }
            return entity;

        }


        /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override int Save()
        {

            if (this.ID == 0)
            {
                this.ID = GetMax("tb_PurchaseInfo");
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into  tb_PurchaseInfo (");
            strSql.Append("[ID],[名称],[编号],[供应商],[品牌],[类别],[型号],[单位],[规格],[采购价],[批发价],[零售价],[送货人],[数量],[进货时间],[备注],[是否包含税],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] )");
            strSql.Append(" values (");
            strSql.Append("@ID,@名称,@编号,@供应商,@品牌,@类别,@型号,@单位,@规格,@采购价,@批发价,@零售价,@送货人,@数量,@进货时间,@备注,@是否包含税,@CreateDate,@CreateBy,@ModifyDate,@ModifyBy)");

            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, this.ID);
            db.AddInParameter(dbCommand, "名称", DbType.String, this.名称);
            db.AddInParameter(dbCommand, "编号", DbType.String, this.编号);
            if (this.供应商 == null)
            {
                db.AddInParameter(dbCommand, "供应商", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "供应商", DbType.Int32, this.供应商.Value);
            }
            db.AddInParameter(dbCommand, "品牌", DbType.String, this.品牌);
            db.AddInParameter(dbCommand, "类别", DbType.String, this.类别);
            db.AddInParameter(dbCommand, "型号", DbType.String, this.型号);
            db.AddInParameter(dbCommand, "单位", DbType.String, this.单位);
            db.AddInParameter(dbCommand, "规格", DbType.String, this.规格);
            if (this.采购价 == null)
            {
                db.AddInParameter(dbCommand, "采购价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "采购价", DbType.Decimal, this.采购价.Value);
            }
            if (this.批发价 == null)
            {
                db.AddInParameter(dbCommand, "批发价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "批发价", DbType.Decimal, this.批发价.Value);
            }
            if (this.零售价 == null)
            {
                db.AddInParameter(dbCommand, "零售价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "零售价", DbType.Decimal, this.零售价.Value);
            }
            db.AddInParameter(dbCommand, "送货人", DbType.String, this.送货人);
            db.AddInParameter(dbCommand, "数量", DbType.String, this.数量);
            if (this.进货时间 == null)
            {
                db.AddInParameter(dbCommand, "进货时间", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "进货时间", DbType.DateTime, this.进货时间.Value);
            }
            db.AddInParameter(dbCommand, "备注", DbType.String, this.备注);
            if (this.是否包含税 == null)
            {
                db.AddInParameter(dbCommand, "是否包含税", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "是否包含税", DbType.Decimal, this.是否包含税.Value);
            }
            if (this.CreateDate == null)
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, this.CreateDate.Value);
            }
            if (this.CreateBy == null)
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, this.CreateBy.Value);
            }
            if (this.ModifyDate == null)
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, this.ModifyDate.Value);
            }
            if (this.ModifyBy == null)
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, this.ModifyBy.Value);
            }

            return db.ExecuteNonQuery(dbCommand);


        }



        /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override int Save(tbPurchaseInfoEntity entity)
        {

            if (entity.ID == 0)
            {
                entity.ID = GetMax("tb_PurchaseInfo");
            }
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into  tb_PurchaseInfo (");
            strSql.Append("[ID],[名称],[编号],[供应商],[品牌],[类别],[型号],[单位],[规格],[采购价],[批发价],[零售价],[送货人],[数量],[进货时间],[备注],[是否包含税],[CreateDate],[CreateBy],[ModifyDate],[ModifyBy] )");
            strSql.Append(" values (");
            strSql.Append("@ID,@名称,@编号,@供应商,@品牌,@类别,@型号,@单位,@规格,@采购价,@批发价,@零售价,@送货人,@数量,@进货时间,@备注,@是否包含税,@CreateDate,@CreateBy,@ModifyDate,@ModifyBy)");

            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID);
            db.AddInParameter(dbCommand, "名称", DbType.String, entity.名称);
            db.AddInParameter(dbCommand, "编号", DbType.String, entity.编号);
            if (entity.供应商 == null)
            {
                db.AddInParameter(dbCommand, "供应商", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "供应商", DbType.Int32, entity.供应商.Value);
            }
            db.AddInParameter(dbCommand, "品牌", DbType.String, entity.品牌);
            db.AddInParameter(dbCommand, "类别", DbType.String, entity.类别);
            db.AddInParameter(dbCommand, "型号", DbType.String, entity.型号);
            db.AddInParameter(dbCommand, "单位", DbType.String, entity.单位);
            db.AddInParameter(dbCommand, "规格", DbType.String, entity.规格);
            if (entity.采购价 == null)
            {
                db.AddInParameter(dbCommand, "采购价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "采购价", DbType.Decimal, entity.采购价.Value);
            }
            if (entity.批发价 == null)
            {
                db.AddInParameter(dbCommand, "批发价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "批发价", DbType.Decimal, entity.批发价.Value);
            }
            if (entity.零售价 == null)
            {
                db.AddInParameter(dbCommand, "零售价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "零售价", DbType.Decimal, entity.零售价.Value);
            }
            db.AddInParameter(dbCommand, "送货人", DbType.String, entity.送货人);
            db.AddInParameter(dbCommand, "数量", DbType.String, entity.数量);
            if (entity.进货时间 == null)
            {
                db.AddInParameter(dbCommand, "进货时间", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "进货时间", DbType.DateTime, entity.进货时间.Value);
            }
            db.AddInParameter(dbCommand, "备注", DbType.String, entity.备注);
            if (entity.是否包含税 == null)
            {
                db.AddInParameter(dbCommand, "是否包含税", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "是否包含税", DbType.Decimal, entity.是否包含税.Value);
            }
            if (entity.CreateDate == null)
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, entity.CreateDate.Value);
            }
            if (entity.CreateBy == null)
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, entity.CreateBy.Value);
            }
            if (entity.ModifyDate == null)
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, entity.ModifyDate.Value);
            }
            if (entity.ModifyBy == null)
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, entity.ModifyBy.Value);
            }

            return db.ExecuteNonQuery(dbCommand);


        }


        /// <summary>
        /// 保存或者更新(如果传入的实体主键为空则保存,否则做更新操作)
        /// </summary>
        /// <param name="entity">传入的实体</param>
        /// <returns>影响的行数</returns>
        public override int SaveOrUpdate(tbPurchaseInfoEntity entity)
        {

            if (entity.ID == 0)
            {
                if (Save(entity) > 0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                return Update(entity);
            }
        }

        /// <summary>
        /// 保存或者更新(如果传入的实体主键为空则保存,否则做更新操作)
        /// </summary>
        /// <param name="entity">传入的实体</param>
        /// <returns>影响的行数</returns>
        public override int SaveOrUpdate()
        {

            if (this.ID == 0)
            {
                if (Save() > 0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                return Update();
            }
        }

        /// <summary>
        /// 是否存在对应主键ID的记录
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public override bool IsExist(int ID)
        {
            Database db = GetDatabase();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from tb_PurchaseInfo where ID=@ID ");

            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, ID);//这里为ID是因为原有代码把主键都变成了ID.
            int cmdresult;
            object obj = db.ExecuteScalar(dbCommand);
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }


        /// <summary>
        /// 删除对应的实体
        /// </summary>
        /// <param name="entity"></param>
        public override int Delete(tbPurchaseInfoEntity entity)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete tb_PurchaseInfo ");
            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID);
            return db.ExecuteNonQuery(dbCommand);
        }

        /// <summary>
        /// 删除主键ID对应的记录
        /// </summary>
        /// <param name="id"></param>
        public override int Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete tb_PurchaseInfo ");
            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, id);
            return db.ExecuteNonQuery(dbCommand);
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public override int Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update tb_PurchaseInfo set ");
            strSql.Append("[ID]=@ID,[名称]=@名称,[编号]=@编号,[供应商]=@供应商,[品牌]=@品牌,[类别]=@类别,[型号]=@型号,[单位]=@单位,[规格]=@规格,[采购价]=@采购价,[批发价]=@批发价,[零售价]=@零售价,[送货人]=@送货人,[数量]=@数量,[进货时间]=@进货时间,[备注]=@备注,[是否包含税]=@是否包含税,[CreateDate]=@CreateDate,[CreateBy]=@CreateBy,[ModifyDate]=@ModifyDate,[ModifyBy]=@ModifyBy ");

            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, this.ID);
            db.AddInParameter(dbCommand, "名称", DbType.String, this.名称);
            db.AddInParameter(dbCommand, "编号", DbType.String, this.编号);
            if (this.供应商 == null)
            {
                db.AddInParameter(dbCommand, "供应商", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "供应商", DbType.Int32, this.供应商.Value);
            }
            db.AddInParameter(dbCommand, "品牌", DbType.String, this.品牌);
            db.AddInParameter(dbCommand, "类别", DbType.String, this.类别);
            db.AddInParameter(dbCommand, "型号", DbType.String, this.型号);
            db.AddInParameter(dbCommand, "单位", DbType.String, this.单位);
            db.AddInParameter(dbCommand, "规格", DbType.String, this.规格);
            if (this.采购价 == null)
            {
                db.AddInParameter(dbCommand, "采购价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "采购价", DbType.Decimal, this.采购价.Value);
            }
            if (this.批发价 == null)
            {
                db.AddInParameter(dbCommand, "批发价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "批发价", DbType.Decimal, this.批发价.Value);
            }
            if (this.零售价 == null)
            {
                db.AddInParameter(dbCommand, "零售价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "零售价", DbType.Decimal, this.零售价.Value);
            }
            db.AddInParameter(dbCommand, "送货人", DbType.String, this.送货人);
            db.AddInParameter(dbCommand, "数量", DbType.String, this.数量);
            if (this.进货时间 == null)
            {
                db.AddInParameter(dbCommand, "进货时间", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "进货时间", DbType.DateTime, this.进货时间.Value);
            }
            db.AddInParameter(dbCommand, "备注", DbType.String, this.备注);
            if (this.是否包含税 == null)
            {
                db.AddInParameter(dbCommand, "是否包含税", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "是否包含税", DbType.Decimal, this.是否包含税.Value);
            }
            if (this.CreateDate == null)
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, this.CreateDate.Value);
            }
            if (this.CreateBy == null)
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, this.CreateBy.Value);
            }
            if (this.ModifyDate == null)
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, this.ModifyDate.Value);
            }
            if (this.ModifyBy == null)
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, this.ModifyBy.Value);
            }


            return db.ExecuteNonQuery(dbCommand);

        }





        /// <summary>
        /// 更新一条数据
        /// </summary>
        public override int Update(tbPurchaseInfoEntity entity)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update tb_PurchaseInfo set ");
            strSql.Append("[ID]=@ID,[名称]=@名称,[编号]=@编号,[供应商]=@供应商,[品牌]=@品牌,[类别]=@类别,[型号]=@型号,[单位]=@单位,[规格]=@规格,[采购价]=@采购价,[批发价]=@批发价,[零售价]=@零售价,[送货人]=@送货人,[数量]=@数量,[进货时间]=@进货时间,[备注]=@备注,[是否包含税]=@是否包含税,[CreateDate]=@CreateDate,[CreateBy]=@CreateBy,[ModifyDate]=@ModifyDate,[ModifyBy]=@ModifyBy ");

            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID);
            db.AddInParameter(dbCommand, "名称", DbType.String, entity.名称);
            db.AddInParameter(dbCommand, "编号", DbType.String, entity.编号);
            if (entity.供应商 == null)
            {
                db.AddInParameter(dbCommand, "供应商", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "供应商", DbType.Int32, entity.供应商.Value);
            }
            db.AddInParameter(dbCommand, "品牌", DbType.String, entity.品牌);
            db.AddInParameter(dbCommand, "类别", DbType.String, entity.类别);
            db.AddInParameter(dbCommand, "型号", DbType.String, entity.型号);
            db.AddInParameter(dbCommand, "单位", DbType.String, entity.单位);
            db.AddInParameter(dbCommand, "规格", DbType.String, entity.规格);
            if (entity.采购价 == null)
            {
                db.AddInParameter(dbCommand, "采购价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "采购价", DbType.Decimal, entity.采购价.Value);
            }
            if (entity.批发价 == null)
            {
                db.AddInParameter(dbCommand, "批发价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "批发价", DbType.Decimal, entity.批发价.Value);
            }
            if (entity.零售价 == null)
            {
                db.AddInParameter(dbCommand, "零售价", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "零售价", DbType.Decimal, entity.零售价.Value);
            }
            db.AddInParameter(dbCommand, "送货人", DbType.String, entity.送货人);
            db.AddInParameter(dbCommand, "数量", DbType.String, entity.数量);
            if (entity.进货时间 == null)
            {
                db.AddInParameter(dbCommand, "进货时间", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "进货时间", DbType.DateTime, entity.进货时间.Value);
            }
            db.AddInParameter(dbCommand, "备注", DbType.String, entity.备注);
            if (entity.是否包含税 == null)
            {
                db.AddInParameter(dbCommand, "是否包含税", DbType.Decimal, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "是否包含税", DbType.Decimal, entity.是否包含税.Value);
            }
            if (entity.CreateDate == null)
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, entity.CreateDate.Value);
            }
            if (entity.CreateBy == null)
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, entity.CreateBy.Value);
            }
            if (entity.ModifyDate == null)
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, entity.ModifyDate.Value);
            }
            if (entity.ModifyBy == null)
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, entity.ModifyBy.Value);
            }


            return db.ExecuteNonQuery(dbCommand);

        }







        /// <summary>
        /// 对象实体绑定数据
        ///生成构造为list的构造器
        /// </summary>
        private tbPurchaseInfoEntity ReaderBind(IDataReader dataReader, int seq)
        {
            ITOMMS.Entity.tbPurchaseInfoEntity entity = new ITOMMS.Entity.tbPurchaseInfoEntity();
            entity.SEQNO = seq;
            object obj;
            obj = dataReader["ID"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ID = (int)obj;
            }
            entity.名称 = dataReader["名称"].ToString();
            entity.编号 = dataReader["编号"].ToString();
            obj = dataReader["供应商"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.供应商 = (int)obj;
            }
            entity.品牌 = dataReader["品牌"].ToString();
            entity.类别 = dataReader["类别"].ToString();
            entity.型号 = dataReader["型号"].ToString();
            entity.单位 = dataReader["单位"].ToString();
            entity.规格 = dataReader["规格"].ToString();
            obj = dataReader["采购价"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.采购价 = (decimal)obj;
            }
            obj = dataReader["批发价"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.批发价 = (decimal)obj;
            }
            obj = dataReader["零售价"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.零售价 = (decimal)obj;
            }
            entity.送货人 = dataReader["送货人"].ToString();
            entity.数量 = dataReader["数量"].ToString();
            obj = dataReader["进货时间"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.进货时间 = (DateTime)obj;
            }
            entity.备注 = dataReader["备注"].ToString();
            obj = dataReader["是否包含税"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.是否包含税 = (bool)obj;
            }
            obj = dataReader["CreateDate"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.CreateDate = (DateTime)obj;
            }
            obj = dataReader["CreateBy"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.CreateBy = (int)obj;
            }
            obj = dataReader["ModifyDate"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ModifyDate = (DateTime)obj;
            }
            obj = dataReader["ModifyBy"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ModifyBy = (int)obj;
            }

            return entity;
        }


        /// <summary>
        /// 对象实体绑定数据
        ///生成构造为list的构造器
        /// </summary>
        private tbPurchaseInfoEntity ReaderBind(IDataReader dataReader)
        {
            ITOMMS.Entity.tbPurchaseInfoEntity entity = new ITOMMS.Entity.tbPurchaseInfoEntity();
            object obj;
            obj = dataReader["ID"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ID = (int)obj;
            }
            entity.名称 = dataReader["名称"].ToString();
            entity.编号 = dataReader["编号"].ToString();
            obj = dataReader["供应商"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.供应商 = (int)obj;
            }
            entity.品牌 = dataReader["品牌"].ToString();
            entity.类别 = dataReader["类别"].ToString();
            entity.型号 = dataReader["型号"].ToString();
            entity.单位 = dataReader["单位"].ToString();
            entity.规格 = dataReader["规格"].ToString();
            obj = dataReader["采购价"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.采购价 = (decimal)obj;
            }
            obj = dataReader["批发价"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.批发价 = (decimal)obj;
            }
            obj = dataReader["零售价"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.零售价 = (decimal)obj;
            }
            entity.送货人 = dataReader["送货人"].ToString();
            entity.数量 = dataReader["数量"].ToString();
            obj = dataReader["进货时间"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.进货时间 = (DateTime)obj;
            }
            entity.备注 = dataReader["备注"].ToString();
            obj = dataReader["是否包含税"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.是否包含税 = (bool)obj;
            }
            obj = dataReader["CreateDate"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.CreateDate = (DateTime)obj;
            }
            obj = dataReader["CreateBy"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.CreateBy = (int)obj;
            }
            obj = dataReader["ModifyDate"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ModifyDate = (DateTime)obj;
            }
            obj = dataReader["ModifyBy"];
            if (obj != null && obj != DBNull.Value)
            {
                entity.ModifyBy = (int)obj;
            }

            return entity;
        }



        #endregion

    }
}
